<?php
##############################################
#
#   奖品表
# @ Time : 2017-1-8 - 下午9:20:27
# @ Author : JiangYongWei <1085562810@qq.com>
# @ Encoding : UTF-8 language : PHP
#
##############################################


namespace Admin\Model;


class PrizeModel extends AdminBaseModel{
	/*奖品表 */
	protected $tableName = 'prize';	
	
	/**
	 * 获取所有奖品
	 */
	public function getPrize($prize_name, $prize_type){
		if($prize_name){
			$map['prize_name'] = array('like','%'.$prize_name.'%');
		}
		if($prize_type){
			$map['prize_type'] = $prize_type;
		}
	    $count = $this -> where($map) -> count();// 查询满足要求的总记录数
	    $Page = new \Think\Page($count, 10);
	    $show = $Page -> show();
	    $result = $this -> where($map) ->order('p_id desc') ->limit($Page->firstRow.','.$Page->listRows) -> select();
		return array($result, $show);
	}

	/**
	  *添加奖品
	  */	
	public function addPrize($data = array()){
		return $this -> add($data);
	}

	/**
	  *获取一行奖品
	  */
	public function getPrizeFind($p_id){
		return $this -> where("p_id = $p_id") -> find();
	}

	public function editPrize($data){
		return $this -> where("p_id = {$data['p_id']}") -> save($data);
	}

	/**
	  * 删除奖品
	  */
	public function deletePrize($p_id){
		return $this -> where("p_id = $p_id") -> delete();
	}
	
	/**
	  *获取全部奖品
	  */
	public function getAllPrizeNum(){
		return $this->getField('prize_num',true);
	}
	
	public function deleteAllPrize($idArr) {
	    foreach ($idArr['rule_id'] as $k => $v){
	        $this->where("p_id = $v")->delete();
	    }
	    return true;
	}
	
}